package com.zhang.zxx.boot.common.core.listener;

import cn.hutool.json.JSONUtil;
import com.zhang.zxx.boot.common.core.event.LogEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * MyEventListener:spring发布事件监听器
 *
 * @author zhangxiaoxiang
 * @date 2021/11/27
 */
@Slf4j
@Component
public class MyEventListener {
    /**
     * 同步事件推送监听
     * @param event 同步事件
     */
    @EventListener(classes = LogEvent.class)
    public void logEvent(LogEvent event) {
        log.info("LogEvent日志事件：{}", JSONUtil.toJsonStr(event));
    }

    /**
     * 异步事件推送监听
     * @param event 异步事件
     */
    @Async
    @EventListener(classes = LogEvent.class)
    public void asyncLogEvent(LogEvent event) {
        log.info("asyncLogEvent日志事件：{}", JSONUtil.toJsonStr(event));
    }
}
